<?php

namespace app\modules\adminapi\controllers;

use app\models\searchs\ClientFilterInterface;
use yii\data\ActiveDataFilter;

class BaseConfigController extends BaseActiveController
{
    public $searchModelClass = '';

    public function actions()
    {
        $actions = parent::actions();

        // 禁用 "delete" 和 "create" 动作
//        unset($actions['delete'], $actions['create']);

        // 使用 "prepareDataProvider()" 方法自定义数据 provider
        $actions['index']['dataFilter'] = [
            'class' => ActiveDataFilter::class,
            'searchModel' => $this->searchModelClass,
        ];

        return $actions;
    }

    public function actionConfigs()
    {
        $class = $this->searchModelClass;

        /** @var  $searchModel ClientFilterInterface*/
        $searchModel = new $class();

        return [
            'filter' => $searchModel->filters(),
            'filterLabels' => $searchModel->attributeLabels(),
            'filterTypes' => $searchModel->attributeTypes()
        ];
    }

}
